import 'package:casdon/modules/me/data/api/browsing_recipe_history_api.dart';
import 'package:casdon/modules/recipe/data/model/recipe_placeholder_data.dart';

class BrowsingRecipeHistoryModel {
  final String title;
  final String mainImg;
  final String author;
  final String createTime;
  final String id;
  final bool isSmart;

  BrowsingRecipeHistoryModel({
    required this.title,
    required this.mainImg,
    required this.author,
    required this.createTime,
    required this.id,
    required this.isSmart,
  });

  // 静态方法转换
  static BrowsingRecipeHistoryModel fromApi(RecipeHistory response) {
    return BrowsingRecipeHistoryModel(
      title: response.name ?? '',
      mainImg: response.mainImg ?? recipePlaceHolderImgUrl,
      author: response.author ?? "匿名用户",
      createTime: response.createTime ?? "",
      id: response.id,
      isSmart: (response.isControl ?? 0) == 1,
    );
  }

  // 批量转换的静态方法
  static List<BrowsingRecipeHistoryModel> listFromApi(
    List<RecipeHistory> items,
  ) {
    return items.map(fromApi).toList();
  }
}
